/*
 * Copyright (C) 2007 Evan Long    longx223 (at) umn (dot) edu
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/**
 * @file   vlc_control.h
 * @author Evan Long
 * 
 * @brief  Provides an interface to create, map commands, and control an 
 * instance of VLC.
 * 
 * 
 */

#ifndef VLC_CONTROL_H
#define VLC_CONTROL_H

/**
 * 7 commands: play, pause, stop, faster, slower, volume up, volume down
 */
#define NCOMMANDS 7

/**
 *Final command line argument that is specified by the user
 */
#define PROGRAM  'p'
#define DEFAULTS 'd'
#define LOAD     'l'

/**
 * Identifiers for the various commands that can be specified to VLC
 */
#define PLAY    0
#define PAUSE   1
#define STOP    2
#define FF      3
#define RR      4
#define VUP     5
#define VDOWN   6

/**
 * Maps the commands of a gesture to a function that will control VLC
 *
 * @param cmdstr Command string that is returned by gesture recognition.
 * @param fcall Function that will be associated with cmdstr. 
 */
typedef struct vlc_command
{
  char cmdstr[5];
  void (*fcall)(int);
} vlc_command_t;

/**
 * Stores information about an instance of VLC and the mappings of various 
 * gestures.
 *
 * @param vlcid Id to VLC that is returned by the VLC API.
 * @param cmd All the different commands that can be mapped to a laser gesture.
 */
typedef struct vlc_control
{
  int vlcid;
  vlc_command_t cmd[NCOMMANDS];
} vlc_control_t;

/** 
 * Creates a new instance of vlc_control_t. Gestures can be mapped in one of 
 * three ways: program mode (PROGRAM), config file mode(LOAD), and default mode
 * (DEFAULTS). In progam mode the user is asked to enter in the gesture by 
 * performing it. In config file mode the text commands that are returned from 
 * the gesture recognition are entered in the following order (one on each 
 * line): play, pause, stop, fast forward, slow down, volume up, volume down. 
 * In default mode the gestures are mapped to a predefined set of defaults.
 * 
 * @param argc Argument count that will be passed to VLC API.
 * @param argv Arguments that will be passed to VLC API.
 * 
 * @return Pointer to a newly allocated instance of vlc_control_t.
 */
vlc_control_t* new_vlc_control(int argc, char** argv);

/** 
 * Utility function that sets the gesture mappings to the predefined defaults. 
 * 
 * @param con Instance of vlc_control_t to modify.
 */
void set_vlc_defaults(vlc_control_t* con);

/** 
 * Sets the command to the specified gesture
 * 
 * @param con 
 * @param command 
 * @param geseture 
 */
void set_vlc_command(vlc_control_t* con, 
		     const char* command, 
		     const char* gesture);

/** 
 * Searches through all the mappings and calls the associated function for a 
 * given command. If there is no matching command then the state of the
 * existing vlc_control_t instance goes unchanged.
 * 
 * @param con Instance of vlc_control_t to control. 
 * @param cmd Command string to search for.
 */
void exec_vlc_command(vlc_control_t* con, char *cmd);

/** 
 * Save out the current gesture mappings to the configuration file.
 * 
 * @param con Instance of vlc_control_t
 */
void save_vlc_command(vlc_control_t* con);

/** 
 * Sends play command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_play_wrap(int vlcid);

/** 
 * Sends pause command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_pause_wrap(int vlcid);

/** 
 * Sends stop command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_stop_wrap(int vlcid);

/** 
 * Sends speed up command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_ff_wrap(int vlcid);

/** 
 * Sends slow down command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_rr_wrap(int vlcid);

/** 
 * Sends volume up command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_vup_wrap(int vlcid);

/** 
 * Sends volume down command to VLC.
 * 
 * @param vlcid Id of instance that is returned by VLC API.
 */
void vlc_vdown_wrap(int vlcid);

#endif

